<template>
  <div>
    <van-nav-bar title="大交通预订首页" left-text="返回" left-arrow @click-left="onClickLeft" />
    <div class="van_card">
      <div class="van_card_title">会议基本信息</div>
    </div>

    <van-cell-group>
      <van-cell title="会议ID号：" :value="meetingInfo.IDNo" />
      <van-cell title="会议地点：" :value="meetingInfo.Place" />
      <van-cell title="会议状态：" :value="Status_mod[meetingInfo.Status]" />
      <van-cell title="会议名称：" :value="meetingInfo.Name" />
      <van-cell title="会议开始日期：" :value="new Date(meetingInfo.StartDate).format('yyyy-MM-dd')" />
      <van-cell title="会议结束日期：" :value="new Date(meetingInfo.EndDate).format('yyyy-MM-dd')" />
      <van-cell title="会议描述：" :value="meetingInfo.Description" />
      <van-cell title="行程安排：" :value="meetingInfo.Remark2" />
    </van-cell-group>
    <div class="van_card" v-if="travelStatus.FlightFlag||travelStatus.TrainFlag&&travelStatus.city">
      <div class="van_card_title">票务</div>
      <van-row class="travel_order_group" v-if="travelStatus.FlightFlag">
        <van-col class="travel_order_title" span="5">国内航班</van-col>
        <van-col class="travel_order_right" span="19">
          <van-button
            :disabled="meetingInfo.EventBudgetAmount"
            type="info"
            size="mini"
            @click="book('flight')"
          >机票预订</van-button>
          <van-button
            :disabled="meetingInfo.EventBudgetAmount"
            type="info"
            size="mini"
            @click="change_('flight')"
          >机票改期</van-button>
          <van-button
            :disabled="meetingInfo.EventBudgetAmount"
            type="info"
            size="mini"
            @click="refund_('flight')"
          >机票退票</van-button>
        </van-col>
      </van-row>
      <van-row class="travel_order_group" style="margin: 5px 0" v-if="travelStatus.TrainFlag">
        <van-col class="travel_order_title" span="5">火车</van-col>
        <van-col class="travel_order_right" span="19">
          <van-button
            :disabled="meetingInfo.EventBudgetAmount"
            type="info"
            size="mini"
            @click="book('train')"
          >火车预订</van-button>
          <van-button
            :disabled="meetingInfo.EventBudgetAmount"
            type="info"
            size="mini"
            @click="change_('train')"
          >火车改期</van-button>
          <van-button
            :disabled="meetingInfo.EventBudgetAmount"
            type="info"
            size="mini"
            @click="refund_('train')"
          >火车退票</van-button>
        </van-col>
      </van-row>
      <div class="warining_info">混合交通出行、商务舱、商务座、高级软卧等需特批舱位请线下联系大交通服务专员40088-40068</div>
    </div>

    <van-notice-bar v-else wrapable mode="closeable">
      如您需要大交通预定：
      <br />1. 会议信息配置中未勾选大交通预定
      <br />2. 名单收集信息中大交通信息未填写
    </van-notice-bar>
  </div>
</template>

<script>
import { GUID } from "../utils/dateFomat";
import utils from "../utils/aes2";
import apilist from "../utils/apiList";
export default {
  data() {
    return {
      travelStatus: {},
      Status_mod: {
        "-1": "已取消",
        "-2": "已取消有损失",
        "-3": "已拒绝",
        10: "会议申请",
        11: "组织者确认",
        20: "直线经理预算审批",
        30: "添加需求",
        40: "DOA经理报价审批",
        41: "采购报价审批",
        42: "采购经理报价审批",
        50: "会议执行",
        51: "确认损失费",
        60: "直线经理结算审批",
        65: "DOA结算审批",
        70: "已完成",
      },
      meetingInfo: {},
    };
  },
  created() {
    this.travelStatus = JSON.parse(sessionStorage.getItem("book_trans")) || {};
    this.getMeetingInfo();
  },
  methods: {
    async getMeetingInfo() {
      let { data } = await this.$axios.get(
        apilist[0] + "/GetEvent?eventid=" + this.travelStatus.eventId
      );
      data.meetingstop =
        data.Status == "-1" ||
        data.Status == "-2" ||
        data.Status == "-3" ||
        data.Status == "10" ||
        new Date(data.CollectEndDate).getTime() < new Date().getTime();
      data.EventBudgetAmount = data.meetingstop
        ? true
        : (data.EventBudgetList.length > 0 &&
            data.EventBudgetList[0].BudgetAmount == 0) ||
          data.EventBudgetList.length == 0;
      this.meetingInfo = data;
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    // 退改签预定流程
    change_: function (x) {
      var g = JSON.parse(sessionStorage.getItem("book_trans"));
      var g2 = this.meetingInfo;
      var sf = g.UCICode ? g.UCICode : "TEST00001";
      var psg = {
        name: g.HCPName,
        phone: g.HCPMobile,
        idtype: g.HCPIDType,
        idno: g.HCPIDNo,
        Gender: g.HCPGender,
        eventid: g2.IDNo,
        ifneedapprove:
          g2.IsChangeRefundNeedApprove == "需" ||
          g2.IsChangeRefundNeedApprove == "需要",
        fillname: "",
        approvestafff: g2.TrainSeatLevel,
        meetcont: g.StaffMobile || "",
      };
      if (sessionStorage.getItem("accountname")) {
        var na = JSON.parse(sessionStorage.getItem("accountname"));
        psg.fillname = na.cName;
      }
      if (sf.indexOf("__") != -1) {
        psg.ifneedapprove = true;
      }
      var limit = [g.sd, g.ed, g.HCPCompanyCity, g2.Place];
      var gpsg = utils.encrypt(JSON.stringify(psg));
      if (x === "flight") {
        //flightchangex
        window.location.href =
          "https://ezway.efasco.com/wxapp/flightchangex/index.html?staffid=" +
          sf +
          "&classlevel=Y&from=web&orderid=" +
          g.MnlOrderNo +
          "&tr_no=&language=CN&ischange=Y&organization=&n_guid=0091_PCN&by=roche_flight&l=" +
          limit +
          "&psgx=" +
          gpsg;
      } else if (x === "train") {
        this.$notify({
          type: "danger",
          message: "该项目服务正在调整，若有需要请线下联系旅行顾问:4008840068",
          duration: 2000,
        });
        return;
        // window.location.href =
        //   "https://ezway.efasco.com/wxapp/flightchangex/index.html?staffid=" +
        //   sf +
        //   "&classlevel=Y&from=web&orderid=" +
        //   g.MnlOrderNo +
        //   "&tr_no=&language=CN&ischange=Y&organization=&n_guid=0091_PCN&by=roche_train&l=" +
        //   limit +
        //   "&psgx=" +
        //   gpsg;
      }
    },
    refund_: function (x) {
      var g = JSON.parse(sessionStorage.getItem("book_trans"));
      sessionStorage.setItem("trdetail", JSON.stringify(g));
      this.$router.push({
        path: "/approvelIndividual",
        query: {
          PaxStaffNo: this.travelStatus.UCICode,
          eventid: this.meetingInfo.IDNo,
          Status: "退票",
        },
      });
    },
    book: function (x) {
      var g = JSON.parse(sessionStorage.getItem("book_trans"));
      var g2 = this.meetingInfo;
      var sf = g.UCICode ? g.UCICode : "TEST00001";
      var guid = new GUID();
      var oi = guid.newGUID();
      var limit = [g.sd, g.ed, g.HCPCompanyCity, g2.Place];
      var psg = {
        name: g.HCPName,
        phone: g.HCPMobile,
        idtype: g.HCPIDType,
        idno: g.HCPIDNo,
        Gender: g.HCPGender,
        eventid: g2.IDNo,
        ifneedapprove:
          g2.IsTktNeedApprove == "需" || g2.IsTktNeedApprove == "需要",
        fillname: "",
        approvestafff: g2.TrainSeatLevel,
        meetcont: g.StaffMobile || "",
        api: apilist,
      };
      if (
        g.IsStaffAttendDinnerParty == "P" ||
        g.IsStaffAttendDinnerParty == "p"
      ) {
        if (
          g2.IsWaivedNeedApprove == "需" ||
          g2.IsWaivedNeedApprove == "需要"
        ) {
          psg.ifneedapprove = true;
        } else {
          psg.ifneedapprove = false;
        }
      }
      if (sessionStorage.getItem("accountname")) {
        var na = JSON.parse(sessionStorage.getItem("accountname"));
        psg.fillname = na.cName;
      }
      if (sf.indexOf("__") != -1) {
        psg.ifneedapprove = true;
      }
      // else{
      // 	psg.fillname = g2.OwnerName;
      // }
      var gpsg = utils.encrypt(JSON.stringify(psg));
      //填写人 是否审批出票 审批人的staffid
      this.$axios
        .get(apilist[1] + "/GetRocheEventFee?eventid=" + g2.IDNo)
        .then((e) => {
          if (e.data > g2.EventBudgetList[0].BudgetAmount) {
            this.$notify({
              type: "danger",
              message: "当前会议的大交通使用额度已超过预算，请尽快更新预算!",
              duration: 2000,
            });
            return;
          }
          if (x === "flight") {
            window.location.href =
              "https://timas.efasco.com/wxapp/flight-con-h5/index.html?staffid=" +
              sf +
              "&staffidx=" +
              sf +
              "&orderid=" +
              oi +
              "&classlevel=Y&organization=0091_PCN&by=roche_flight&l=" +
              limit +
              "&psgx=" +
              gpsg;
          } else if (x === "train") {
            window.location.href =
              "https://timas.efasco.com/wxapp/flight-con-h5/index.html?staffid=" +
              sf +
              "&staffidx=" +
              sf +
              "&orderid=" +
              oi +
              "&classlevel=Y&organization=0091_PCN&by=roche_train&l=" +
              limit +
              "&psgx=" +
              gpsg;
          }
        });
    },
  },
};
</script>

<style scoped lang="less">
.travel_order_group {
  margin: 5px 0;
  .travel_order_title {
    line-height: 34px;
  }
  .travel_order_right {
    .van-button--mini {
      width: 32%;
      height: 34px;
    }
  }
}
.van-notice-bar{
  margin-top: 10px;
}
.warining_info {
  color: red;
  font-weight: 600;
  margin-top: 20px;
}
</style>